//
//  CZVisitorTableViewController.swift
//  WeiBO28
//
//  Created by 飞奔的羊 on 16/5/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZVisitorTableViewController: UITableViewController {
    //用户是否登录的标记
    var userLogin = CZUserAccountViewModel.shareUserAccount.isLogin
    
    var vistourView: CZVisitorView?
    
    override func loadView() {
        if userLogin {
        super.loadView()
            
        }else{
        //没有登录的情况下,提供自定义访客视图
            vistourView = CZVisitorView()
            
            vistourView!.callBackClosure = {
            [weak self] in
            self?.requestOAuthLogin()
            }
//            v.backgroundColor = UIColor.yellowColor()
            view = vistourView
//创建按钮
            
        setupNavUI()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

     
        
    }

    private func setupNavUI() {
        
      
        
        
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", fontSize: 15, target: self, action: #selector(CZVisitorTableViewController.registerAction))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", fontSize: 15, target: self, action: #selector(CZVisitorTableViewController.loginAction))
    
    }
  
    
    // MARK: ------点击事件------
    
    //注册
   @objc private func registerAction() {
    
    requestOAuthLogin()
    }
    
    //登录
   @objc private func loginAction() {
    
    requestOAuthLogin()
    }
    
    
    
    private func requestOAuthLogin() {
    
    let oauthVC = CZOAuth()
        
        let nav = UINavigationController(rootViewController: oauthVC)
        
       presentViewController(nav, animated: true, completion: nil)
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
}
